using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace ClubWebsite
{
    public partial class EditPageOption : System.Web.UI.UserControl
    {
        public delegate void SaveChangesClickedEventHandler();
        public event SaveChangesClickedEventHandler SaveChangesClicked;

        protected void Page_Load(object sender, EventArgs e)
        {
            // Hide all controls by default
            HideAllControls();

            if ((Session["EditPage"] is Guid) && ((Guid)Session["EditPage"] == ((Default)Page.Master).PageID))
            {
                btnSave.Visible = true;
                btnCancel.Visible = true;
            }
            else
            {
                Session.Remove("EditPage");
                btnEditPage.Visible = true;
            }
        }

        private void HideAllControls()
        {
            btnEditPage.Visible = false;
            btnSave.Visible = false;
            btnCancel.Visible = false;
        }

        protected void btnEditPage_Click(object sender, EventArgs e)
        {
            Session["EditPage"] = ((Default)Page.Master).PageID;
            Response.Redirect(Request.RawUrl.ToString());
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Session.Remove("EditPage");
            Response.Redirect(Request.RawUrl.ToString());
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (SaveChangesClicked != null)
            {
                SaveChangesClicked();
            }
        }
    }
}